package com.xuecheng.media.api.controller;

import com.xuecheng.base.exception.XCPlusException;
import com.xuecheng.base.model.RestResponse;
import com.xuecheng.base.utils.StringUtil;
import com.xuecheng.media.model.po.MediaFiles;
import com.xuecheng.media.service.MediaFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:王亚栋
 * @Date:2023/8/6 19:13
 * @Version:1.0
 */
@RestController
@Api(value = "媒资文件管理接口",tags = "媒资文件管理接口")
@RequestMapping("open")
@Slf4j(topic = "媒资文件公开管理接口")
public class MediaOpenController {

    @Autowired
    private MediaFileService mediaFileService;

    @ApiOperation("预览文件")
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable("mediaId") String mediaId){

       MediaFiles mediaFiles =  mediaFileService.getFileById(mediaId);
       log.info("查询到的mediaFiles:{}",mediaFiles);

       if (mediaFiles == null || StringUtils.isEmpty(mediaFiles.getUrl())){

           XCPlusException.cast("视频还没有转码处理！");
       }

       return RestResponse.success(mediaFiles.getUrl());

    }
}
